package logic

import (
	"bw-renting/model/mysql"
	"context"
	"strconv"

	"bw-renting/house-rpc/house"
	"bw-renting/house-rpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateHouseFacilityLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCreateHouseFacilityLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateHouseFacilityLogic {
	return &CreateHouseFacilityLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// TODO: 添加房源设施
func (l *CreateHouseFacilityLogic) CreateHouseFacility(in *house.CreateHouseFacilityReq) (*house.Response, error) {
	// todo: add your logic here and delete this line
	//获取设施名称
	FacilityName := mysql.GetFacilityName(mysql.Facility{
		Id: uint64(in.FacilityId),
	})
	//创建房源设施
	facility := mysql.CreateHouseFacility(mysql.HouseFacility{
		Name:    FacilityName,
		HouseId: in.HouseId,
	})
	if facility.Id == 0 {
		return &house.Response{
			Status: "0",
		}, nil
	}
	return &house.Response{
		Status: strconv.Itoa(int(in.HouseId)),
	}, nil
}
